package com.example.newlist.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;

import com.example.newlist.R;
import com.example.newlist.bean;

import java.util.ArrayList;

public class MyAdapter extends BaseExpandableListAdapter {

    public ArrayList<bean> list;
    public MyAdapter(ArrayList<bean> list){
        this.list = list;
    }

    @Override
    public int getGroupCount() {
        return list.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return list.size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return groupPosition;
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.exgrouplist,parent,false);
        TextView textView = view.findViewById(R.id.text);
        TextView state = view.findViewById(R.id.state);
        textView.setText(list.get(groupPosition).getGroupText());
        if (isExpanded) {
            state.setText("开");
        } else {
            state.setText("关");
        }
        return view;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.exitemlayout,parent,false);
        TextView textView = view.findViewById(R.id.itemText);
        textView.setText(list.get(groupPosition).getGroupText());
        return view;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}
